package com.deyuanyun.pic.ae.controller.vo;

import com.deyuanyun.pic.ae.domain.TrafficFacilities;
import com.deyuanyun.pic.ae.enumeration.PositionRelationEnum;
import com.deyuanyun.pic.ae.enumeration.YesOrNoEnum;
import com.deyuanyun.pic.common.util.NumberUtil;
import com.deyuanyun.pic.common.util.format.NumberFormat;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.pipe.util.PipeMgrUtil;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


/**
 * E_2交通设施信息表
 */
public class TrafficFacilitiesVO extends AEBaseVO<TrafficFacilities>{

    // 管道名称
    private String pipeLineName;
    // 类型AETRAFFIC_TYPE（公路、铁路、高铁、地铁、高架、其它）
    private String type;
    // 名称
    private String name;
    // 所属单位
    private String owner;
    // 联系人/单位
    private String contact;
    // 联系方式
    private String telephone;

    // 平行段起点_绝对里程
    private String beginMileage;
    // 平行起点_附近测试桩pic_pipe_identification.ID_
    private String beginNagm;
    // 平行起点_附近测试桩距离（相对值）
    private String beginNagmMileage;
    // 平行段终点_绝对里程
    private String endMileage;
    // 平行段终点_附近测试桩pic_pipe_identification.ID_
    private String endNagm;
    // 平行段终点_附近测试桩距离（相对值）
    private String endNagmMileage;
    // 起点位置描述
    private String beginDescription;
    // 终点位置描述
    private String endDescription;
    // 最小平行间距（m）
    private String minDistance;
    // 平行长度（m）
    private BigDecimal parallelLength;

    // 交叉段_绝对里程
    private String crossMileage;
    // 交叉段_附近测试桩pic_pipe_identification.ID_
    private String crossNagm;
    // 交叉段_附近测试桩距离（相对值）
    private String crossNagmMileage;
    // 位置描述
    private String locationDescription;
    // 垂直间距（m）
    private String altitudeSeparation;

    // 相对位置关系（交叉、平行）CROSS、PARALLEL
    private String relativePositionRelation;
    // 是否为安全间距（YES、NO）
    private String safeHeight;
    // 数据状态
    private String dataStated;
    private String gisid;

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getBeginMileage() {
        return beginMileage;
    }

    public void setBeginMileage(String beginMileage) {
        this.beginMileage = beginMileage;
    }

    public String getBeginNagm() {
        return beginNagm;
    }

    public void setBeginNagm(String beginNagm) {
        this.beginNagm = beginNagm;
    }

    public String getBeginNagmMileage() {
        return beginNagmMileage;
    }

    public void setBeginNagmMileage(String beginNagmMileage) {
        this.beginNagmMileage = beginNagmMileage;
    }

    public String getEndMileage() {
        return endMileage;
    }

    public void setEndMileage(String endMileage) {
        this.endMileage = endMileage;
    }

    public String getEndNagm() {
        return endNagm;
    }

    public void setEndNagm(String endNagm) {
        this.endNagm = endNagm;
    }

    public String getEndNagmMileage() {
        return endNagmMileage;
    }

    public void setEndNagmMileage(String endNagmMileage) {
        this.endNagmMileage = endNagmMileage;
    }

    public String getBeginDescription() {
        return beginDescription;
    }

    public void setBeginDescription(String beginDescription) {
        this.beginDescription = beginDescription;
    }

    public String getEndDescription() {
        return endDescription;
    }

    public void setEndDescription(String endDescription) {
        this.endDescription = endDescription;
    }

    public String getMinDistance() {
        return minDistance;
    }

    public void setMinDistance(String minDistance) {
        this.minDistance = minDistance;
    }

    public BigDecimal getParallelLength() {
        return parallelLength;
    }

    public void setParallelLength(BigDecimal parallelLength) {
        this.parallelLength = parallelLength;
    }

    public String getCrossMileage() {
        return crossMileage;
    }

    public void setCrossMileage(String crossMileage) {
        this.crossMileage = crossMileage;
    }

    public String getCrossNagm() {
        return crossNagm;
    }

    public void setCrossNagm(String crossNagm) {
        this.crossNagm = crossNagm;
    }

    public String getCrossNagmMileage() {
        return crossNagmMileage;
    }

    public void setCrossNagmMileage(String crossNagmMileage) {
        this.crossNagmMileage = crossNagmMileage;
    }

    public String getLocationDescription() {
        return locationDescription;
    }

    public void setLocationDescription(String locationDescription) {
        this.locationDescription = locationDescription;
    }

    public String getAltitudeSeparation() {
        return altitudeSeparation;
    }

    public void setAltitudeSeparation(String altitudeSeparation) {
        this.altitudeSeparation = altitudeSeparation;
    }

    public String getRelativePositionRelation() {
        return relativePositionRelation;
    }

    public void setRelativePositionRelation(String relativePositionRelation) {
        this.relativePositionRelation = relativePositionRelation;
    }

    public String getSafeHeight() {
        return safeHeight;
    }

    public void setSafeHeight(String safeHeight) {
        this.safeHeight = safeHeight;
    }

    public String getDataStated() {
        return dataStated;
    }

    public void setDataStated(String dataStated) {
        this.dataStated = dataStated;
    }

    public String getGisid() {
        return gisid;
    }

    public void setGisid(String gisid) {
        this.gisid = gisid;
    }

    @Override
    public void fromDomain(TrafficFacilities domain) {

        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 类型AETRAFFIC_TYPE（公路、铁路、高铁、地铁、高架、其它）
        this.type = CodeUtil.getName(domain.getType());
        // 名称
        this.name = domain.getName();
        // 所属单位
        this.owner = domain.getOwner();
        // 联系人/单位
        this.contact = domain.getContact();
        // 联系方式
        this.telephone = domain.getTelephone();

        if (PositionRelationEnum.PARALLEL.toString().equals(domain.getRelativePositionRelation())) {
            // 平行段起点_绝对里程
            this.beginMileage = NumberFormat.format(NumberUtil.toMeter(domain.getBeginMileage()), NumberFormat.FMT_PLACES3);
            // 平行起点_附近测试桩pic_pipe_identification.ID_
//        this.beginNagm = PipeMgrUtil.getIdentificationNumber(domain.getBeginNagm());
            this.beginNagm = domain.getBeginNagmNumber();
            // 平行起点_附近测试桩距离（相对值）
            this.beginNagmMileage = NumberFormat.format(NumberUtil.toMeter(domain.getBeginNagmMileage()), NumberFormat.FMT_PLACES3);
            // 平行段终点_绝对里程
            this.endMileage = NumberFormat.format(NumberUtil.toMeter(domain.getEndMileage()), NumberFormat.FMT_PLACES3);
            // 平行段终点_附近测试桩pic_pipe_identification.ID_
//        this.endNagm = PipeMgrUtil.getIdentificationNumber(domain.getEndNagm());
            this.endNagm = domain.getEndNagmNumber();
            // 平行段终点_附近测试桩距离（相对值）
            this.endNagmMileage = NumberFormat.format(NumberUtil.toMeter(domain.getEndNagmMileage()), NumberFormat.FMT_PLACES3);
            // 起点位置描述
            this.beginDescription = domain.getBeginDescription();
            // 终点位置描述
            this.endDescription = domain.getEndDescription();
            // 最小平行间距（m）
            this.minDistance = NumberFormat.format(domain.getMinDistance(), NumberFormat.FMT_PLACES3);
            // 平行长度（m）
            this.parallelLength = domain.getParallelLength();
        } else {
            // 交叉段_绝对里程
            this.crossMileage = NumberFormat.format(NumberUtil.toMeter(domain.getCrossMileage()), NumberFormat.FMT_PLACES3);
            // 交叉段_附近测试桩pic_pipe_identification.ID_
//        this.crossNagm = PipeMgrUtil.getIdentificationNumber(domain.getCrossNagm());
            this.crossNagm = domain.getCrossNagmNumber();
            // 交叉段_附近测试桩距离（相对值）
            this.crossNagmMileage = NumberFormat.format(NumberUtil.toMeter(domain.getCrossNagmMileage()), NumberFormat.FMT_PLACES3);
            // 位置描述
            this.locationDescription = domain.getLocationDescription();
            // 垂直间距（m）
            this.altitudeSeparation = NumberFormat.format(domain.getAltitudeSeparation(), NumberFormat.FMT_PLACES3);
        }

        // 相对位置关系（交叉、平行）CROSS、PARALLEL
        this.relativePositionRelation = PositionRelationEnum.getLabel(domain.getRelativePositionRelation());
        // 是否为安全间距（YES、NO）
        this.safeHeight = YesOrNoEnum.getLabel(domain.getSafeHeight());
        // 数据状态
        this.dataStated = domain.getDataStated();
        this.gisid = domain.getGisid();

        super.fromDomain(domain.getId(), domain.getRecorder(), domain.getRecordTime(), domain.getRemarks());
    }

    public Page<TrafficFacilitiesVO> fromDomainList(Page<TrafficFacilities> domainList) {
        Page<TrafficFacilitiesVO> list = new Page<TrafficFacilitiesVO>();
        for (TrafficFacilities trafficFacilities : domainList) {
            TrafficFacilitiesVO trafficFacilitiesVO = new TrafficFacilitiesVO();
            trafficFacilitiesVO.fromDomain(trafficFacilities);
            list.add(trafficFacilitiesVO);
        }
        BaseVOUtil.converterPage(domainList, list);
        return list;
    }

    public ExportObj fromDomainList(List<TrafficFacilities> domainList) {
        ExportObj exportObj = new ExportObj();
        List<TrafficFacilitiesVO> postList = new ArrayList<TrafficFacilitiesVO>();
        List<TrafficFacilitiesVO> lineList = new ArrayList<TrafficFacilitiesVO>();
        for (TrafficFacilities trafficFacilities : domainList) {
            TrafficFacilitiesVO trafficFacilitiesVO = new TrafficFacilitiesVO();
            trafficFacilitiesVO.fromDomain(trafficFacilities);
            if (PositionRelationEnum.CROSS.toString().equals(trafficFacilities.getRelativePositionRelation())){
                postList.add(trafficFacilitiesVO);
            } else {
                lineList.add(trafficFacilitiesVO);
            }
        }
        exportObj.setPostList(postList);
        exportObj.setLineList(lineList);
        return exportObj;
    }

    public static class ExportObj {

        private List<TrafficFacilitiesVO> postList;
        private List<TrafficFacilitiesVO> lineList;

        public List<TrafficFacilitiesVO> getPostList() {
            return postList;
        }

        public void setPostList(List<TrafficFacilitiesVO> postList) {
            this.postList = postList;
        }

        public List<TrafficFacilitiesVO> getLineList() {
            return lineList;
        }

        public void setLineList(List<TrafficFacilitiesVO> lineList) {
            this.lineList = lineList;
        }
    }
}